<template>
	<div class="page">
		<!-- <div class="search-view">
			<Input v-model="search" icon="ios-search"  placeholder="Enter something..." style="width: 3.6rem"></Input>
		</div> -->
		<div class="list-view">
			<XOrderListView 
			:data="orderData"
			@on-action="clickAction"
			@on-change-page="changePage"
			@on-change-pageSize="changePageSize"></XOrderListView>
		</div>
	</div>
</template>

<script>
import $ from 'jquery'
import productService from '@/network/service/productService.js'
import XOrderListView from '@/pages/order/view/XOrderListView'
export default {
	components: {
		XOrderListView
	},
	data() {
		return {
			search: '',
			orderData: {
				isLoading: false,
				data: [],
				listType: 'page',
				page: {
					currentPage: 0,
					pagesize: 20,
					totalSize: 0
				}
			},
		}
	},
	mounted() {
		let input = $('.ivu-input');
		let table = $('.ivu-table');
		let selects = $('.ivu-select');
		let select = $('.ivu-page-options-elevator input');
		for(let i = 0; i < input.length; i++) {
			input[i].style.color = 'rgba(255, 255, 255, 0.6)'
		}
		for(let i = 0; i < table.length; i++) {
			table[i].style.color = 'rgba(255, 255, 255, 0.6)'
		}
		for(let i = 0; i < select.length; i++) {
			select[i].style.color = 'rgba(255, 255, 255, 0.6)'
		}
		for(let i = 0; i < selects.length; i++) {
			selects[i].style.color = 'rgba(255, 255, 255, 0.6)'
		}
		this.orderList();
	},
	methods: {
		changePage(page) {
			this.orderData.page.currentPage = page - 1;
			this.orderList();
		},
		changePageSize(pageSize) {
			this.orderData.page.pagesize = pageSize;
			this.orderList();
		},
		clickAction(formData) {
			this.$Modal.confirm({
				title: '配送',
				content: '是否配送完成',
				onOk: () => {
					this.deliverComplete(formData);
				}
			});
		},


		orderList() {
			let params = {
				page: this.orderData.page.currentPage,
				pageSize: this.orderData.page.pagesize
			}
			productService.orderList(params).then(res => {
				let result = res.data;
				let code = result.rescode;
				if (code == 100) {
					this.orderData.data = result.data;
					this.orderData.page.totalSize = result.totalSize;
				}
			}, error => {
				this.$Message.error('服务器异常，请稍后再试')
			})
		},
		deliverComplete(formData) {
			productService.deliverComplete(formData.row.oid).then(res => {
				let result = res.data;
				let code = result.rescode;
				let resmsg = result.msg;
				if (code == 100) {
					formData.row.deliverStatus = 1;
				} else {
					this.$Message.error(resmsg);
				}
			}, error => {
				this.$Message.error('服务器异常，请稍后再试')
			})
		}
	}
}
</script>

<style scoped lang="less">
.page {
	width: 100%;
	height: 100%;
	padding: .1rem .1rem 0 .1rem;
	color: #fff;
	overflow: auto;
	.search-view {
		position: relative;
		margin-bottom: .4rem;
	}
}
</style>